package com.zhangshuo.patternDesign.mediator;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shuo.zhang on 2017-10-24.
 *
 * 门派联盟的实现类
 *
 *
 */
public class PatternAlliance implements IPatternAlliance {

    private List<School> schoolList;

    public PatternAlliance(){
        schoolList = new ArrayList<>();
    }


    @Override
    public void add(School school) {
        schoolList.add(school);
    }

    @Override
    public void resolveAttack(School activeSide, School passiveSide) {
        if (schoolList.contains(activeSide) && schoolList.contains(passiveSide)){
            System.out.println(activeSide.getName() + " 与 " + passiveSide.getName() + " 为同一联盟不能内讧");
            return ;
        }

        if(schoolList.contains(activeSide)){
            System.out.println("主攻方 " + activeSide.getName() + " 加入了联盟全体攻击");
            for(School allianceSchool : schoolList){
                allianceSchool.attack(passiveSide);
            }
            return ;
        }

        System.out.println("主攻方 "+ activeSide.getName() + " 不在联盟中，联盟不干预此事");
        activeSide.attack(passiveSide);

    }

    @Override
    public void resolveDefense(School passiveSide) {
        if(schoolList.contains(passiveSide)){
            System.out.println("防御方 " + passiveSide.getName() + "加入了联盟所有同盟防御");
            for(School allianceSchool : schoolList){
                allianceSchool.attack(passiveSide);
            }
            return ;
        }

        System.out.println("防御方 " + passiveSide.getName() + "未加入联盟联盟不干涉");
        passiveSide.defense();
    }
}
